/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/*
*  \class	TAngle
*  \author 	Jari Saarinen
*  \date 	Fri Mar 10 12:25:17 2006

*  \version: 	0.1  
*/


#include "TAngle.h"




TAngle::TAngle()
{
 this->a = 0;	
}

TAngle::TAngle(float a){
 this->a = a;
}
TAngle::~TAngle()
{
	
}

/**
* Returns the angle value
*/
float TAngle::getValue(){
	return a;
}

/**
* Return the angle in degrees
*/
float TAngle::getDegValue(){
	return RAD2DEG(this->a);
}

/**
* Sets the angle to given value 
*/
void TAngle::setValue(float a){
	this->a = a;
}

void TAngle::setDegreesValue(float deg){
	this->a = DEG2RAD(deg);
}

/**
 * Scales the given angle to between 0 and 2*PI
 * 
 * @param val Angle to scale
 * @return Scaled angle.
 */
float TAngle::to2pi(float val) {
	while(val < 0) {
		val += 2*(float)M_PI;
	}
	while(val > 2*M_PI) {
		val -= 2*(float)M_PI;
	}
	return val;
}

/**
 * Scales the given angle to between 0 and 2*PI
 * 
 * @param val Angle to scale
 * @return Scaled angle.
 */
void TAngle::to2pi() {
	this->a = to2pi(this->a);
}


TAngle TAngle::operator +(TAngle x) const{
	return TAngle(x.a + a);
}

TAngle TAngle::operator -( TAngle x) const{
	return TAngle(x.a - a);
}

TAngle TAngle::operator +(float y) const{
	return TAngle(a + y);
}
TAngle TAngle::operator -(float y) const{
	return TAngle(a - y);
}

TAngle& TAngle::operator =(const float &a){
	this->a = a;
	return *this;
}
TAngle& TAngle::operator =( const double &a){
	this->a = (float) a;
	return *this;
}
